import * as Cesium from "cesium"
import { DrawerBase } from "./DrawerBase"
import type { EventsConfig } from "./DrawerBase"

/**
 * @author Oo青花鱼
 * @description 点绘制
 * @example
 * //实例化Drawer
 * const drawer = new PointDrawer(viewer);
 * drawer.start() //开始绘制
 * drawer.end() //结束绘制
 * drawer.clear() //清空绘制的图形
 * drawer.destroy() //销毁实例
 * drawer.data //访问绘制的Entity
 * drawer.onClose = (entity:Cesium.Entity)=>{
 *    console.log('绘制了一个点',entity)
 * }
 */
export class PointDrawer extends DrawerBase {
  //辅助实体
  protected helpers: Cesium.Entity.ConstructorOptions[] = [
    {
      position: new Cesium.CallbackPositionProperty(() => {
        return this.mousePosition
      }, false),
      point: {},
    },
  ]

  //事件配置
  protected events: EventsConfig = {
    cesiumEvents: [
      {
        type: "click",
        callback: (e: Cesium.ScreenSpaceEventHandler.PositionedEvent) => {
          const position = this.scene.pickPosition(e.position)
          this.drawFeature({
            position,
            point: {},
            properties: {
              type: "point",
            },
          })
        },
      },
    ],
  }
}
